package com.bwie.bwedu.activity;

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;

import com.bwie.bwedu.R;
import com.bwie.bwedu.fragment.MessageSettingFragment;
import com.bwie.bwedu.fragment.PasswordUpdFragment;

/**
 * Created by Administrator on 2016/7/21.
 * 个人中心信息修改界面
 */
public class PersonalInfoUpdActivity extends BaseActivity {

    private ImageButton back;
    private TextView title;
    private String position;

    @Override
    public int getLayout() {
        return R.layout.activity_personal_upd;
    }

    @Override
    public void findView() {
        back = (ImageButton) findViewById(R.id.item_title_back);
        title = (TextView) findViewById(R.id.item_title_title);
    }

    @Override
    public void setData() {
        FragmentManager manager = getSupportFragmentManager();
        position = getIntent().getStringExtra("position");
        FragmentTransaction transaction = manager.beginTransaction();
        if ("0".equals(position)){
            transaction.add(R.id.personal_upd_fl,new PasswordUpdFragment(),"password");
            title.setText("修改密码");
        }else{
            transaction.add(R.id.personal_upd_fl,new MessageSettingFragment(),"message");
            title.setText("消息设置");
        }
        transaction.commit();
    }

    @Override
    public void setListener() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBack();
            }
        });
    }

    private void onBack() {
        finish();
        overridePendingTransition(R.anim.leftenter,R.anim.rightexit);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode==KeyEvent.KEYCODE_BACK) {
            onBack();
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}
